/*
*	ID : Pallab
* 	PROG : 5902
* 	LANG : C++
* 	2012-11-29-20.19.22 Thursday
*
* 	"I have not failed, I have just found 10000 ways that won't work.
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <numeric>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define foR(i1,st,ed) for(int i1 = st , j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i1,ed) foR( i1 , 0 , ed )
#define foE(i1,st,ed) foR( i1, st, ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

inline void wait(double seconds) {
    double endtime = clock() + (seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}
template<class T>
inline T fastIn() {
    register char c=0;
    register T a=0;
    bool neg=false;
    while(c<33)c=getchar();
    while(c>33) {
        if(c=='-') {
            neg=true;
        } else {
            a= (a*10)+(c-'0');
        }
        c=getchar();
    }
    return neg?-a:a;
}
struct Node {
    int key, priority, size;
    Node* left, *right;
    Node(int k, int p) :
        key(k), priority(p), left(NULL), right(NULL), size(1) {
    }
    Node(int k) :
        key(k), left(NULL), right(NULL), priority(rand()), size(1) {
    }
};
inline int sz(Node *root) {
    if (root == NULL)
        return 0;
    return root->size;
}
inline void upd(Node *root) {
    if (root != NULL) {
        root->size = 1 + sz(root->left) + sz(root->right);
    }
    return ;
}
Node* search(Node *root, int key) {
    if (root == NULL)
        return NULL;
    if (key < root->key)
        return search(root->left, key);
    if (key > root->key)
        return search(root->right, key);
    return root;
}
Node* rotRight(Node *root) {
    Node* pivot = root->left;
    root->left = pivot->right;
    pivot->right = root;
    upd(root->right),upd(root);
    return pivot;
}

Node* rotLeft(Node *root) {
    Node* pivot = root->right;
    root->right = pivot->left;
    pivot->left = root;
    upd(root->left),upd(root);
    return pivot;
}
Node* insert(Node *root, Node *novo) {
    if (root == NULL)
        return novo;
    if (root->key < novo->key) {
        root->right = insert(root->right, novo);
        if (root->right->priority > root->priority)
            root = rotLeft(root);
    } else {
        root->left = insert(root->left, novo);
        if (root->left->priority > root->priority)
            root = rotRight(root);
    }
    upd(root);
    return root;
}

Node* erase(Node* root, int key) {
    if (root == NULL) {
        return root;
    }
    if (root->key < key)
        root->right = erase(root->right, key);
    else if (root->key > key)
        root->left = erase(root->left, key);
    else {
        if (root->left != NULL) {
            if (root->right != NULL) {
                if (root->left->priority < root->right->priority) {
                    root = rotLeft(root);
                    root->left = erase(root->left, key);
                } else {
                    root = rotRight(root);
                    root->right = erase(root->right, key);
                }
            } else {
                Node* aux = root->left;
                delete root;
                return aux;
            }
        } else {
            if (root->right != NULL) {
                Node* aux = root->right;
                delete root;
                return aux;
            } else {
                delete root;
                return NULL;
            }
        }
    }
    upd(root);
    return root;
}
Node * Find_kth_Node(Node *root, int k) {
    if (sz(root) < k)
        return NULL;
    int ans = 1 + sz(root->left);
    if (ans == k)
        return root;
    if (ans < k)
        return Find_kth_Node(root->right, k - ans);
    return Find_kth_Node(root->left, k);
}
int count_less(Node *root, int k) {
    if (root == NULL)
        return 0;
    if(root->key<k) {
        return 1+sz(root->left)+ count_less(root->right,k);
    }
    return count_less(root->left,k);
}
Node* clear(Node* root) {
    if (root != NULL) {
        clear(root->left);
        clear(root->right);
        delete root;
    }
}

void Traverse(Node *root, int level) {
    if (root == NULL)
        return;
    printf("[%d = > %d,%d,%d]->\n", level, root->key, root->priority,
           root->size);
    Traverse(root->left, level + 1);
    Traverse(root->right, level + 1);
}

const int MX = (int)1e5+5;
int number_count,query_count;
int queries[MX];
inline void read() {
    number_count=fastIn<int>(),query_count=fastIn<int>();
    fo(i,query_count) {
        queries[i]=fastIn<int>()-1;
    }
}
int decode[MX];
inline void proc() {
    Node *treap = NULL;
    fo(i,number_count) {
        decode[i]=i;
        treap = insert(treap, new Node(decode[i]) );
    }
    int nxt_insert=-1;
    fo(i,query_count) {
        int num = queries[i];
        int tmp = decode[num];
        int ans = count_less(treap,tmp);
        if(i)cout<<' ';
        cout<<ans;
        treap = erase(treap, tmp);
        decode[num]=nxt_insert--;
        treap = insert(treap, new Node(decode[num]));
    }
    line;
    clear(treap);
}
int main() {
    int kase = 1;
#if defined( xerxes_pc )
    if (!freopen("in1", "r", stdin))
        puts("error opening file in "), assert(0);
    kase = 1;
#endif
    kase=fastIn<int>();
    fo(i,kase) {
        read();
        proc();
    }
    return 0;
}
